﻿using System;
using System.Windows.Input;
using Collab.Modules.ContactBrowser.ViewModel;

namespace Collab.Modules.ContactBrowser.Commands
{
    public class LoginCommand : ICommand
    {
        private readonly LoginViewModel _vm;

        public bool CanLogin { get; set; }

        public LoginCommand(LoginViewModel vm)
        {
            _vm = vm;
            CanLogin = true;
        }

        public bool CanExecute(object parameter)
        {
            return !string.IsNullOrEmpty(_vm.Username) && !string.IsNullOrEmpty(_vm.Password) && this.CanLogin;
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public void Execute(object parameter)
        {
            _vm.Login();
        }
    }
}
